//
//  FLPagingScrollViewController.m
//  FeeLing
//
//  Created by 乔光玉 on 2019/1/4.
//  Copyright © 2019年 大仙儿飘. All rights reserved.
//
#import "FLRestorePurchaseViewController.h"
#import "FLPagingScrollViewController.h"

@interface FLPagingScrollViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView * oeeScrollView;
@property (nonatomic, strong) UIPageControl *pageControl;
@end

@implementation FLPagingScrollViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSUserDefaults standardUserDefaults] setObject:@"FLPagingScrollViewController" forKey:@"currentController"];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    self.oeeScrollView  = [[UIScrollView  alloc]init];
    self.oeeScrollView.directionalLockEnabled = YES ;
    self.oeeScrollView.showsHorizontalScrollIndicator = NO;
    self.oeeScrollView.showsVerticalScrollIndicator = NO;
    self.oeeScrollView.indicatorStyle = UIScrollViewIndicatorStyleDefault ;
    self.oeeScrollView.pagingEnabled = YES;
    
    self.oeeScrollView.delegate = self ;
    self.oeeScrollView.backgroundColor = [UIColor whiteColor];
    self.oeeScrollView.contentSize = CGSizeMake(2*SCREENWIDTH, 0);
    [self.view addSubview:self.oeeScrollView];
    [self.oeeScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view.mas_left).with.offset(0);
        make.top.equalTo(self.view.mas_top).with.offset(0);
        make.right.equalTo(self.view.mas_right).with.offset(0);
        make.bottom.equalTo(self.view.mas_bottom).with.offset(0);
        
    }];
    
    
    
    
    
    UIImageView * ImageViewOne = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"引导页1背景"]];
    [self.oeeScrollView addSubview:ImageViewOne];
    [ImageViewOne mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).with.offset(0);
        make.left.equalTo(self.oeeScrollView.mas_left).with.offset(0);
        make.width.mas_equalTo(SCREENWIDTH);
        make.height.mas_equalTo(SCREENHEIGHT);
        
        
    }];
    
    UILabel * onelabelone = [[UILabel alloc]init];
    onelabelone.textAlignment = NSTextAlignmentCenter;
    onelabelone.font = [UIFont fontWithName:@"PingFangSC-Regular" size: 24];
    onelabelone.textColor = [UIColor whiteColor];
    onelabelone.text = NSLocalizedString(@"onelabelone", nil);
    [ImageViewOne addSubview:onelabelone];
    [onelabelone mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(ImageViewOne.mas_bottom).with.offset(-95-60);
        make.centerX.equalTo(ImageViewOne.mas_centerX).with.offset(0);
        
        
        
    }];
    
    
    UILabel * onelabeltwo = [[UILabel alloc]init];
    onelabeltwo.textAlignment = NSTextAlignmentCenter;
    onelabeltwo.font = [UIFont fontWithName:@"PingFangSC-Regular" size: 16];
    onelabeltwo.textColor = [UIColor whiteColor];
    onelabeltwo.text = NSLocalizedString(@"onelabeltwo", nil);
    [ImageViewOne addSubview:onelabeltwo];
    [onelabeltwo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(ImageViewOne.mas_bottom).with.offset(-95);
        make.centerX.equalTo(ImageViewOne.mas_centerX).with.offset(0);
        
        
        
    }];
    
    
    
    UIImageView * ImageViewTwo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"引导页2背景"]];
    [self.oeeScrollView addSubview:ImageViewTwo];
    [ImageViewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).with.offset(0);
        make.left.equalTo(self.oeeScrollView.mas_left).with.offset(SCREENWIDTH);
        make.width.mas_equalTo(SCREENWIDTH);
        make.height.mas_equalTo(SCREENHEIGHT);
        
    }];
    
    UILabel * twolabelone = [[UILabel alloc]init];
    twolabelone.textAlignment = NSTextAlignmentCenter;
    twolabelone.font = [UIFont fontWithName:@"PingFangSC-Regular" size: 24];
    twolabelone.textColor = [UIColor whiteColor];
    twolabelone.text = NSLocalizedString(@"twolabelone", nil);
    [ImageViewTwo addSubview:twolabelone];
    [twolabelone mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(ImageViewTwo.mas_bottom).with.offset(-95-60);
        make.centerX.equalTo(ImageViewTwo.mas_centerX).with.offset(0);
        
        
        
    }];
    
    
    UILabel * twolabeltwo = [[UILabel alloc]init];
    twolabeltwo.textAlignment = NSTextAlignmentCenter;
    twolabeltwo.font = [UIFont fontWithName:@"PingFangSC-Regular" size: 16];
    twolabeltwo.textColor = [UIColor whiteColor];
    twolabeltwo.text = NSLocalizedString(@"twolabeltwo", nil);
    [ImageViewTwo addSubview:twolabeltwo];
    [twolabeltwo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(ImageViewTwo.mas_bottom).with.offset(-95);
        make.centerX.equalTo(ImageViewTwo.mas_centerX).with.offset(0);
        
        
        
    }];
    
    self.pageControl = [[UIPageControl alloc]init];
    self.pageControl.numberOfPages = 2;
    self.pageControl.currentPage=0;
    self.pageControl.currentPageIndicatorTintColor =[UIColor whiteColor] ;
    self.pageControl.pageIndicatorTintColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.35];
    [self.view addSubview:self.pageControl];
    [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.view.mas_bottom).with.offset(-19);
        make.centerX.equalTo(self.view.mas_centerX).with.offset(0);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
        
    }];
    
    
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat scrollViewW = scrollView.frame.size.width;
    
    CGFloat x = scrollView.contentOffset.x;
    
    
    
    int page = (x + scrollViewW/2)/scrollViewW;
    self.pageControl.currentPage =page;
    
    
    CGFloat offsetX = scrollView.contentOffset.x;
    
    if (offsetX>SCREENWIDTH) {
        
        [self hiddenImageView];
    }
    
    
}
- (void)hiddenImageView
{
    
    [UIView animateWithDuration:0.1 animations:^{
        
    } completion:^(BOOL finished) {
        FLRestorePurchaseViewController * vc = [[FLRestorePurchaseViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
